﻿@{
    ViewBag.Title = "样品扫码入库";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="~/Content/Theme/tablenew.css" rel="stylesheet" />
<form method="post" style="height:100%">
    @Html.AntiForgeryToken()
    <div class="querybar" style="padding: 10px 0 10px 5px;background: #fafbfc;border-bottom: 0px solid #eef1f5;">
        <table cellpadding="0" cellspacing="1" border="0" width="100%">
            <tr>
                <td>
                    扫码：<input type="text" class="mytext" id="Code" name="Code" value=""
                              style="width:200px;" />

                    <input type="button" name="Search" onclick="query(0);" value="备检样品入库" class="mybutton" />
                    <input type="button" name="Search1" onclick="query(1);" value="复检样品入库" class="mybutton" />
                    <input type="button" name="Search1" onclick="clerSam();" value="清空样品码" class="mybutton" />
                </td>
            </tr>
        </table>
    </div>
    <div class="querybar" style="background:#ffffff;width:100%">
        <table class="flowformtable tableF table table-bordered" data-sort="sortDisabled" cellspacing="0" cellpadding="0" align="left" width="98%" >
            <tbody>
                <tr>
                    <th class="titleT" rowspan="1" colspan="2" valign="middle" align="left">
                        <p class="titleO">
                            样品信息
                        </p>
                    </th>
                </tr>
                <tr class="topTr">
                    <td class="top" rowspan="1" colspan="2" valign="middle" align="left">
                        <p class="txt">
                            存储位置
                        </p><textarea type1="flow_textarea" id="address" name="address" class="mytext" style="height:40px;width:80%;"></textarea>
                    </td>
                </tr>
                <tr class="bottomTr">
                    <td class="bottom" rowspan="1" colspan="2" valign="middle" align="left">
                        <p class="txt">
                            样品码
                        </p><textarea type1="flow_textarea" readonly="readonly" id="bgbhs" name="bgbhs" class="mytext" value="" style="height:80px;width:80%; background:#CCCCCC"></textarea>
                    </td>
                </tr>
            </table>
    </div>
</form>
<script type="text/javascript">

    var isFilst = true;
    $(function () {
        var jsUserName = "";
        if (!+[1,])        // IE浏览器
        {
            $("#Code").get(0).onpropertychange = setJsCodeName;
        }
        else        // 其他浏览器
        {
            var intervalName;        // 定时器句柄
            $("#Code").get(0).addEventListener("input", setJsCodeName, false);
            // 获得焦点时，启动定时器
            $("#Code").focus(function () {
                intervalName = setInterval(handle, 1000);
            });

            // 失去焦点时，清除定时器
            $("#Code").blur(function () {
                clearInterval(intervalName);
            });
        }
        // 设置jsUserName input的值
        function setJsCodeName() {
            var code = $(this).val();
            if (isEmpty1(code)) {
                return;
            }
            var bgbhs = $("#bgbhs").val();
            if (isFilst) {
                bgbhs = $.trim(code);
                $("#bgbhs").val(bgbhs);
                $(this).val('');
                isFilst = false;
                return;
            }
            if (bgbhs.indexOf(code) == -1) { //等于-1表示这个字符串中没有o这个字符
                bgbhs = $.trim(bgbhs) + ',' + $.trim(code);
                $("#bgbhs").val(bgbhs);
                $(this).val('');
                return;
                
            }
        }
        function handle() {
            // IE浏览器此处判断没什么意义，但为了统一，且提取公共代码而这样处理。
            //if ($("#jsUserName").val() != jsUserName) {
            //    $("#toolTip").remove();
            //    $("#jsUserName").parent().append("<span id='toolTip'>看到这里的信息表明，通过js改变input的值也能响应相应事件：<span    style='color:red;'>" + $("#jsUserName").val() + "</span></span>");
            //    jsUserName = $("#jsUserName").val();
            //}
        }
    });
    function clerSam() {
        $("#bgbhs").val('');
        isFilst = true;
    }
    //判断字符是否为空的方法
    function isEmpty1(obj) {
        if (typeof obj == "undefined" || obj == null || obj == ""||obj=="/n") {
            return true;
        } else {
            return false;
        }
    }
    function query(type)
    {
        var timestamp = new Date().getTime();
        var form1 = document.forms[0];
        if ($.trim(form1.bgbhs.value).length == 0) {
            alert("样品码不能为空!");
            return false;
        }
        if ($.trim(form1.address.value).length == 0) {
            alert("地址不能为空!");
            return false;
        }
        var url = "/assetmanage/amsample/addsample?type=" + type + "&bgbhs=" + $("#bgbhs").val() + "&address=" + $("#address").val() + "&group=" + timestamp;
        RoadUI.Core.showWait();
        $.ajax({
            //headers: { "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() },
            url: url, contentType: RoadUI.Core.ajaxContentType, type: "Post", dataType: "json", cache: false, async: true,
            success: function (json) {
                if (json.status == 0) {
                    alert("录入错误："+json.msg);
                }
                else {
                    alert("成功录入" + json.data + "条，以下样品码没找到：" + json.msg);
                    clerSam();
                }

                new RoadUI.Window().close();
            },
            error: function (json) {
                RoadUI.Core.showError(json);
                new RoadUI.Window().close();
            }
        });
    }
</script>

